﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

public partial class admin_admin : System.Web.UI.MasterPage
{
    public string UserID
    {
        get { return ViewState["userid"].ToString(); }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        lnkbtnExit.Click += new EventHandler(lnkbtnExit_Click);
        if (!IsPostBack)
        {
            if (null != Session["userid"])
            {
                ViewState["userid"] = Session["userid"].ToString();
                InitNav();
            }
            else
            {
                System.Web.Security.FormsAuthentication.RedirectToLoginPage();
            }
        }
    }

    void lnkbtnExit_Click(object sender, EventArgs e)
    {
        Session["userid"] = null;
        ViewState["userid"] = null;
        System.Web.Security.FormsAuthentication.RedirectToLoginPage();
    }

    private void InitNav()
    {
        string url = Request.Url.AbsoluteUri.ToLower();
        if (url.LastIndexOf("/") > 0 && url.Length > url.LastIndexOf("/"))
        {
            url = url.Substring(url.LastIndexOf("/") + 1);
        }
        //url = url.Substring(0, url.LastIndexOf("."));

        StringBuilder sb = new StringBuilder();
        #region 引导页
        sb.Append("<div class=\"title\" onclick=\"title_Click(this);\">基本设置</div>");
        sb.Append("<dl>");
        sb.Append("<dt " + (url.ToLower() == "indexs.aspx" ? "class=\"cur\"" : "") + "><a href=\"indexs.aspx\">引导页</a></dt>");
        sb.Append("<dt " + (url.ToLower() == "home.aspx?s=1" ? "class=\"cur\"" : "") + "><a href=\"home.aspx?s=1\">首页弹窗</a></dt>");
        sb.Append("<dt " + (url.ToLower() == "home.aspx?s=2" ? "class=\"cur\"" : "") + "><a href=\"home.aspx?s=2\">全部产品列表</a></dt>");
        sb.Append("</dl>");
        #endregion

        #region 关于斯帝博
        sb.Append("<div class=\"title\" onclick=\"title_Click(this);\">关于斯帝博</div>");
        sb.Append("<dl>");
        sb.Append("<dt " + (url.ToLower() == "item_edit.aspx?s=1" ? "class=\"cur\"" : "") + "><a href=\"item_edit.aspx?s=1\">添加新项目</a></dt>");
        sb.Append("<dt " + (url.ToLower() == "items.aspx?s=1" ? "class=\"cur\"" : "") + "><a href=\"items.aspx?s=1\">项目管理</a></dt>");
        sb.Append("</dl>");
        #endregion

        #region 新闻动态
        sb.Append("<div class=\"title\" onclick=\"title_Click(this);\">新闻动态</div>");
        sb.Append("<dl>");
        sb.Append("<dt " + (url.ToLower() == "news_edit.aspx" ? "class=\"cur\"" : "") + "><a href=\"news_edit.aspx\">添加新闻</a></dt>");
        sb.Append("<dt " + (url.ToLower() == "news.aspx" ? "class=\"cur\"" : "") + "><a href=\"news.aspx\">管理新闻</a></dt>");
        sb.Append("</dl>");
        #endregion

        #region 核心技术
        sb.Append("<div class=\"title\" onclick=\"title_Click(this);\">核心技术</div>");
        sb.Append("<dl>");
        sb.Append("<dt " + (url.ToLower() == "item_edit.aspx?s=2" ? "class=\"cur\"" : "") + "><a href=\"item_edit.aspx?s=2\">添加技术</a></dt>");
        sb.Append("<dt " + (url.ToLower() == "items.aspx?s=2" ? "class=\"cur\"" : "") + "><a href=\"items.aspx?s=2\">项目管理</a></dt>");
        sb.Append("</dl>");
        #endregion

        #region 热水系列解决方案
        sb.Append("<div class=\"title\" onclick=\"title_Click(this);\">热水系列解决方案</div>");
        sb.Append("<dl>");
        sb.Append("<dt "+(url.ToLower() == "item_edit.aspx?s=3"?"class=\"cur\"" : "")+"><a href=\"item_edit.aspx?s=3\">添加新方案</a></dt>");
        sb.Append("<dt " + (url.ToLower() == "items.aspx?s=3" ? "class=\"cur\"" : "") + "><a href=\"items.aspx?s=3\">项目管理</a></dt>");
        sb.Append("</dl>");
        #endregion

        #region 精品世界
        sb.Append("<div class=\"title\" onclick=\"title_Click(this);\">精品世界</div>");
        sb.Append("<dl>");
        sb.Append("<dt " + (url.ToLower() == "product_edit.aspx" ? "class=\"cur\"" : "") + "><a href=\"product_edit.aspx\">添加产品</a></dt>");
        sb.Append("<dt " + (url.ToLower() == "products.aspx" ? "class=\"cur\"" : "") + "><a href=\"products.aspx\">产品列表</a></dt>");
        sb.Append("</dl>");
        #endregion

        #region 服务用户
        sb.Append("<div class=\"title\" onclick=\"title_Click(this);\">服务用户</div>");
        sb.Append("<dl>");
        sb.Append("<dt " + (url.ToLower() == "item_edit.aspx?s=4" ? "class=\"cur\"" : "") + "><a href=\"item_edit.aspx?s=4\">添加新服务</a></dt>");
        sb.Append("<dt " + (url.ToLower() == "items.aspx?s=4" ? "class=\"cur\"" : "") + "><a href=\"items.aspx?s=4\">项目管理</a></dt>");
        sb.Append("</dl>");
        #endregion

        #region 代理商用户
        sb.Append("<div class=\"title\" onclick=\"title_Click(this);\">服务代理商</div>");
        sb.Append("<dl>");
        sb.Append("<dt " + (url.ToLower() == "file_edit.aspx" ? "class=\"cur\"" : "") + "><a href=\"file_edit.aspx\">添加文件</a></dt>");
        sb.Append("<dt " + (url.ToLower() == "files.aspx" ? "class=\"cur\"" : "") + "><a href=\"files.aspx\">管理文件</a></dt>");
        sb.Append("<dt " + (url.ToLower() == "agent_edit.aspx" ? "class=\"cur\"" : "") + "><a href=\"agent_edit.aspx\">添加代理商</a></dt>");
        sb.Append("<dt " + (url.ToLower() == "agents.aspx" ? "class=\"cur\"" : "") + "><a href=\"agents.aspx\">代理商管理</a></dt>");
        sb.Append("</dl>");
        #endregion

        #region 全球供应商
        sb.Append("<div class=\"title\" onclick=\"title_Click(this);\">全球供应商</div>");
        sb.Append("<dl>");
        sb.Append("<dt " + (url.ToLower() == "item_edit.aspx?s=5" ? "class=\"cur\"" : "") + "><a href=\"item_edit.aspx?s=5\">添加项目</a></dt>");
        sb.Append("<dt " + (url.ToLower() == "items.aspx?s=5" ? "class=\"cur\"" : "") + "><a href=\"items.aspx?s=5\">项目管理</a></dt>");
        sb.Append("</dl>");
        #endregion

        #region 联系我们
        sb.Append("<div class=\"title\" onclick=\"title_Click(this);\">联系我们</div>");
        sb.Append("<dl>");
        sb.Append("<dt " + (url.ToLower() == "item_edit.aspx?s=6" ? "class=\"cur\"" : "") + "><a href=\"item_edit.aspx?s=6\">添加项目</a></dt>");
        sb.Append("<dt " + (url.ToLower() == "items.aspx?s=6" ? "class=\"cur\"" : "") + "><a href=\"items.aspx?s=6\">项目管理</a></dt>");
        sb.Append("</dl>");
        #endregion

        #region 基础设置
        sb.Append("<div class=\"title\" onclick=\"title_Click(this);\">基础设置</div>");
        sb.Append("<dl>");
        CAdmin admin = new CAdmin();
        DataRow r = admin.ReadUser(int.Parse(ViewState["userid"].ToString()));
        if (r["userrole"].ToString() == "0")
        {
            //用户管理
            sb.Append("<dt " + (url.ToLower() == "users.aspx" ? "class=\"cur\"" : "") + "><a href=\"users.aspx\">用户管理</a></dt>");
            //添加用户
            if (url.ToLower() == "user_edit.aspx" && null == Request.QueryString["id"])
            {
                sb.Append("<dt class=\"cur\"><a href=\"user_edit.aspx\">添加新用户</a></dt>");
            }
            else
            {
                sb.Append("<dt><a href=\"user_edit.aspx\">添加新用户</a></dt>");
            }
        }
        //修改密码
        sb.Append("<dt " + (url.ToLower() == "password.aspx" ? "class=\"cur\"" : "") + "><a href=\"password.aspx\">修改密码</a></dt>");
        sb.Append("</dl>");
        #endregion
        this.ltlLeftNav.Text = sb.ToString();
    }
}
